package com.zff.controller;

import com.zff.tool.QiniuUtil;
import com.zff.tool.WeChatUtil;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;
import org.springframework.web.multipart.MultipartHttpServletRequest;

import javax.servlet.http.HttpServletRequest;
import java.io.File;
import java.io.IOException;
import java.util.List;

/**
 * TODO
 * @version 1.0
 * @author Zff
 * @date 2020/8/20 16:13
 */
@RestController
@RequestMapping("/upload111")
public class UploadController {
    private static final Logger LOGGER = LoggerFactory.getLogger(UploadController.class);

    @PostMapping("/uploadVideo")
    public String upload(MultipartFile file) throws IOException {
        System.out.println(file);
        if (file.isEmpty()) {
            return "上传失败，请选择文件";
        }

        String fileName = file.getOriginalFilename();
       // QiniuUtil.testUpload(file.getBytes(),fileName);
        String filePath = "E:\\test\\";
        File dest = new File(filePath + fileName);
        try {
            file.transferTo(dest);
            LOGGER.info("上传成功");
            return "上传成功";
        } catch (IOException e) {
            LOGGER.error(e.toString(), e);
        }
        return "上传失败！";
    }

}
